package com.zdsoft.crm.service.product.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zdsoft.crm.dao.product.IProductMapper;
import com.zdsoft.crm.entity.product.Product;
import com.zdsoft.crm.entity.product.ProductType;
import com.zdsoft.crm.service.product.IProductService;
import com.zdsoft.crm.vo.PageVo;
@Service
@Transactional
public class ProductServiceImpl implements IProductService{

	@Autowired
	IProductMapper productMapper;
	
	@Override
	public PageVo findPage(Integer pageNum, Integer pageSize) {
		PageVo pageVo = new PageVo();
		pageVo.setPageNum(pageNum);
		pageVo.setPageSize(pageSize);
		int beginIndex = (pageNum - 1) * pageSize;
		int endIndex = beginIndex + pageSize;
		pageVo.setList(productMapper.pageList(beginIndex, endIndex));
		pageVo.setTotalCount(productMapper.totalCount().intValue());
		return pageVo;
	}

	@Override
	public void save(Product product) {
		productMapper.save(product);
	}
	@Override
	public int delete(String id) {
		return productMapper.deleteAll(id);
	}


	@Override
	public Product getProductInfo(String id) {
		
		return productMapper.getProductInfo(id);
	}

	@Override
	public List<ProductType> findAll() {
		
		return productMapper.findAll();
	}

	@Override
	public Product finInfo(String id) {
		
		return productMapper.finInfo(id);
	}

	@Override
	public void update(Product product) {
		productMapper.update(product);
	}

	@Override
	public ProductType findByTypeName(String typeName) {
		
		return productMapper.findByTypeName(typeName);
	}

	@Override
	public List<Product> getProAll() {
		// TODO Auto-generated method stub
		return productMapper.getProAll();
	}

	@Override
	public PageVo findPageType(Integer pageNum, Integer pageSize,String typeName) {
		PageVo pageVo = new PageVo();
		pageVo.setPageNum(pageNum);
		pageVo.setPageSize(pageSize);
		int beginIndex = (pageNum - 1) * pageSize;
		int endIndex = beginIndex + pageSize;
		pageVo.setList(productMapper.findPageType(beginIndex, endIndex, typeName));
		pageVo.setTotalCount(productMapper.totalCountType(typeName).intValue());
		return pageVo;
	}

	@Override
	public PageVo pageList1(Integer pageNum, Integer pageSize, String product_type_id) {
		PageVo pageVo = new PageVo();
		pageVo.setPageNum(pageNum);
		pageVo.setPageSize(pageSize);
		int beginIndex = (pageNum - 1) * pageSize;
		int endIndex = beginIndex + pageSize;
		pageVo.setList(productMapper.pageList1(beginIndex, endIndex, product_type_id));
		pageVo.setTotalCount(productMapper.totalCount1(product_type_id).intValue());
		return pageVo;
	}

	@Override
	public void saveType(ProductType productType) {
		productMapper.saveType(productType);
	}

	@Override
	public ProductType findTypeInfo(String id) {
		// TODO Auto-generated method stub
		return productMapper.findTypeInfo(id);
	}

	@Override
	public void updateType(ProductType productType) {
		productMapper.updateType(productType);
	}

	@Override
	public int deleteTypeAll(String id) {
		// TODO Auto-generated method stub
		return productMapper.deleteTypeAll(id);
	}
}
